/*******************************************************************************************************

Figure A6: Distribution of petitions sent, 1820-1829


*******************************************************************************************************/

*Set directory path
cd "C:\Users\tsa23\Documents\petitions\replication files"

*Panel A: Case G

clear all

*read in our main dataset
use dta/did_rep.dta

*Elminate contrituencies which are not part of case G
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if new == 1 | drummond == .

drop if year==1830 | year==1831 | year==1832 /*keep or drop observations from 1830-32*/

gen treatgroup = 0
replace treatgroup =  1 if new==1 

gen treatinter = treatperiod*treatgroup
label var treatinter "ATE" 

collapse treatgroup (sum) petitions, by(ID treatperiod treatinter)
 
label var treatgroup "T"
label var treatperiod "A"
label var treatinter "T $\times$ A"

sort treatgroup
by treatgroup: sum  petitions, detail 
by treatgroup: tabulate  petitions
*3 out of 186 in control; 33b (Bridgmater) 39b (Caernarvon) 170a (New Radnor)
*2 out of 42 in treatment 294 (Merthur Tydvil, before) and 313 (Frome, after)

histogram petitions if treatgroup==0 & petitions<100, width(1) start(0) color(red) fcolor(red%70)  ///
    addplot(histogram petitions if treatgroup==1 & petitions<100, width(1) start(0) color(blue) fcolor(blue%30)) ///
    legend(order(1 "Control" 2 "Treatment")) ///
    xtitle("Petitions") title(" ")
	graph export graphs\figureA6a.pdf, as(pdf) name("Graph")  replace

*Panel B: Case L

clear all

*read in our main dataset
use dta/did_rep.dta

*Elminate contrituencies which are not part of case L
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if sch_A==1 | sch_B == 1 | drummond!=.

drop if year==1830 | year==1831 | year==1832

gen treatgroup = 0
replace treatgroup =  1 if sch_A==1 

gen treatinter = treatperiod*treatgroup
label var treatinter "ATE" 

collapse treatgroup (sum) petitions, by(ID treatperiod treatinter)
 
label var treatgroup "T"
label var treatperiod "A"
label var treatinter "T $\times$ A"

sort treatgroup
by treatgroup: sum  petitions, detail 
by treatgroup: tabulate  petitions
*24 of 56 treatment 13b 11a
*2 of 64 control 1a 1b. 168 (New Lymington)

histogram petitions if treatgroup==0, width(1) start(0) color(red) fcolor(red%70) ///
    addplot(histogram petitions if treatgroup==1, width(1) start(0) color(blue) fcolor(blue%30)) ///
    legend(order(1 "Control" 2 "Treatment")) ///
    xtitle("Petitions") title(" ")

graph export graphs\figureA6b.pdf, as(pdf) name("Graph")  replace
